package edu.gyc.homework;

public class MembershipCard {
    private int id;
    private double balance;
    private double discountRate;

    public MembershipCard(int id, double balance) {
        this.id = id;
        this.balance = balance;
        handleDiscount();
        System.out.println("恭喜你成为我公司的会员，id："+id+" 余额："+balance+" 消费折扣率："+discountRate);
    }

    private void handleDiscount() {
        if(balance>=100000){
            this.discountRate=0.5;
        }
        else if(balance>=50000&&balance<100000){
            this.discountRate=0.8;
        }
        else if(balance>=10000&&balance<50000){
            this.discountRate=0.9;
        }else {
            this.discountRate=1;
        }
    }
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public double getDiscountRate() {
        return discountRate;
    }

    public void setDiscountRate(double discountRate) {
        this.discountRate = discountRate;
    }

    public void pay(double money) {
        if (this.balance >= money*this.discountRate) {
            this.balance-=money*this.discountRate;
            System.out.println("尊敬顾客："+id+",本次消费"+money+",打折后消费"+money*discountRate+",余额为："+balance);
        }else {
            System.out.println("尊敬的顾客"+id +",你的余额不足！");
        }
    }

    public void deposit(double money) {
        this.balance+=money;
         handleDiscount();
        System.out.println("恭喜会员，id："+id+"，充值"+money+" 余额："+balance+"，根据余额消费折扣率调整为："+discountRate);
    }

    public static void main(String[] args) {
        MembershipCard membershipCard = new MembershipCard(1, 100000);
        membershipCard.pay(6000);
        membershipCard.pay(60000);
        membershipCard.deposit(30000);
        membershipCard.pay(5000);
    }
}
